package com.libbase.kotlin.base

import android.arch.lifecycle.LifecycleObserver
import android.os.Bundle
import android.view.View
import com.base.fragment.BaseFragment
import com.base.kotlin.mvp.IView
import com.base.kotlin.mvvm.BaseVmPresenter

/**
 * @author zhouzechao
 * MVVM的Fragment基类，
 */
abstract class BaseVmKFragment<P : BaseVmPresenter<*>> : BaseFragment(), IView.DefaultView {

    protected var mPresenter: P? = null

    abstract fun bindViewToPresenter(): P?

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        mPresenter = bindViewToPresenter()
        mPresenter?.let {
            lifecycle.addObserver(it as LifecycleObserver)
        }
        super.onViewCreated(view, savedInstanceState)
    }

    override fun onDestroy() {
        super.onDestroy()
        mPresenter?.let {
            lifecycle.removeObserver(it as LifecycleObserver)
        }
    }

    override fun onDefaultSuccess(action: Int, data: Any?) {

    }
}